#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <errno.h>
#include <stdarg.h>
#include "write_log.h"


void write_log(const char *__fmt, ...)
{
	char line[MAX_LOG_LEN] = { 0 };
	char strt[MAX_LOG_LEN] = { 0 };

    va_list ap;
    va_start(ap, __fmt);
    vsprintf(line, __fmt, ap);
    va_end(ap);

    // 当前时间
    time_t curtm = time(NULL);
    struct tm tm_struct;
    (void)localtime_r(&curtm, &tm_struct);
    (void)strftime(strt, sizeof(strt)-1, "%T", &tm_struct);

    FILE *pf = fopen(LOG_FILE_PATH, "a+");
    if (pf == NULL)
    {
    	return;
    }
    fprintf(pf, "%s %s\r\n", strt, line);
    fclose(pf);
    pf = NULL;
}























